package com.shanling.shanlingcontroller.persenter

import android.content.Context
import android.util.Log
import com.shanling.shanlingcontroller.music.player.PlayHistoryLoader
import com.shanling.shanlingcontroller.music.player.PlaylistLoader
import com.shanling.shanlingcontroller.music.player.SongLoader
import com.shanling.shanlingcontroller.persenter.contract.HistoryMusicContract
import com.shanling.shanlingcontroller.persenter.contract.MusicListContract
import com.shanling.shanlingcontroller.persenter.contract.SongFragmentContract
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread

/**
 * Created by ch1 on 2019/11/23.
 */
class HistoryMusicPersenter constructor() : RxPresenter<HistoryMusicContract.View>(), HistoryMusicContract.Presenter {
    override fun loadSongs(context: Context?,type:Int) {
        mView?.showLoading()
        Log.e("weiyu","进来了"+type);
        if(type==1){
            doAsync {
                val data= PlayHistoryLoader.getPlayHistory();
                uiThread {
                    mView?.hideLoading()
                    mView?.showSongs(data)
                    if (data.size == 0) {
                        mView?.setEmptyView()
                    }
                }
            }
        }else{
            doAsync {
                val data=  PlaylistLoader.getFavoritePlaylist()
                uiThread {
                    mView?.hideLoading()
                    mView?.showSongs(data)
                    if (data.size == 0) {
                        mView?.setEmptyView()
                    }
                }
            }
        }
    }
}